
class SelfMessage {
  constructor (name, content) {
    this.name = name
    this.content = content
  }
}

class GptMessage {
  constructor (content) {
    this.role = 'user'
    this.content = content
  }
}

export default class Chat {
  constructor () {
    this.messages = []
    this.capacity = 20
  }

  addMessage (name, content) {
    const msg = process.env.IS_SELF_SERVER === '1' ? new SelfMessage(name, content) : new GptMessage(content)
    this.messages.push(msg)
    if (this.messages.length > this.capacity) {
      this.messages.shift()
    }
  }

  getMessage () {
    return this.messages
  }

  popMessage () {
    this.messages.pop()
  }
}
